<script>
import {registerCompanyApi} from "@/api/qingongjianxue";

export default {
  computed: {
    privateKey(){
      return  this.$store.state.app.user_info.privateKey
    }
  },
  props: {

    addCompanyShow: {
      type: Boolean,
      default: false
    }
  },
  data(){
    return {
      companyForm: {
        name: ''
      }
    }
  },
  methods: {
    close(){
      this.$emit('close')
    },
    async createCompany(){
      if(!this.companyForm.name){
        this.$message.error('请输入公司名称')
        return
      }
      try{
        await registerCompanyApi({
          name: this.companyForm.name,
          privateKey: this.privateKey
        })
        this.$message.success('创建公司成功!')
        this.$emit('close')
        this.$emit('success')
      }catch (e){
        this.$message.error('创建公司失败!')
      }
    },
  }
}
</script>

<template>
  <el-dialog title="创建公司" :visible.sync="addCompanyShow" width="30%">
    <el-form>
      <el-form-item label="公司名称">
        <el-input v-model="companyForm.name" placeholder="请输入公司名称"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button size="small" type="info" @click="close">取消</el-button>
      <el-button size="small" type="primary" @click="createCompany">确定</el-button>
    </div>
  </el-dialog>
</template>

<style scoped lang="scss">

</style>
